import HYRequest from './request'
import { BASE_URL, TIME_OUT } from './request/config'
import localCache from '@/utils/cache'

export const hyRequest = new HYRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: (config) => {
      const token = localCache.getCache('token')
      if (token && config.headers) {
        config.headers.Authorization = `Bearer ${token}`
      }
      // console.log('请求成功的拦截')
      return config
    },
    requestInterceptorCatch: (error) => {
      // console.log('请求失败的拦截')

      return error
    },
    responseInterceptor: (res) => {
      // console.log('响应成功的拦截')

      return res
    },
    responseInterceptorCatch: (error) => {
      // console.log('响应失败的拦截')

      return error
    }
  }
})
interface DataType {
  data: any
  returnCode: string
  success: boolean
}

export function getInfo() {
  return hyRequest.get<DataType>({
    url: '/home/multidata',
    interceptors: {
      requestInterceptor: (config) => {
        console.log('接口的拦截器2')

        return config
      }
    }
    // showLoading: false
  })
}
